<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Game</title>
    <style>
    </style>
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
  (async function init(){
      try{
          const player = await getPlayerInfo()
          if(playerExist(player)){
              showPlayerInfo(player)
          }else{
              showCreatePlayer()
          }
      }catch(e){
          alert(e)
      }
  }())

  function showPlayerInfo(player){
      //TODO: 显示角色信息
      console.log(player)
  }

  function getPlayerInfo(){
      return new Promise((resolve,reject) => {
          $.ajax({
              url: '/player/info',
              method: 'POST',
          }).then(res => {
              if(res.ok){
                  resolve(res)
              }else{
                  reject('获取信息出错: '+res.msg)
              }
          },err => {
              reject('服务器响应错误')
          })
      })
  }
</script>
</body>
</html>